﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class lotteryDrawRewardConfig extends Object
    {
        private var _map:Dictionary;
        private static var _instance:lotteryDrawRewardConfig;

        public function lotteryDrawRewardConfig()
        {
            this._map = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" lotteryDrawRewardConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TLotteryItems = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                if (this._map[_loc_3.catagory] == null)
                {
                    this._map[_loc_3.catagory] = new Dictionary();
                }
                if (this._map[_loc_3.catagory][_loc_3.boxLevel] == null)
                {
                    this._map[_loc_3.catagory][_loc_3.boxLevel] = new Array();
                }
                _loc_2 = new TLotteryItems();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                (this._map[_loc_2.catagory][_loc_2.boxLevel] as Array).push(_loc_2);
            }
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_lottery_items.json");
            this.write(_loc_1);
            return;
        }// end function

        public function getShowItemsByLevel(param1:int) : Array
        {
            var boxLevel:* = param1;
            var arr:* = this._map[10001][boxLevel];
            if (arr == null)
            {
                arr = new Array();
            }
            var sortFunc:* = function (param1:TLotteryItems, param2:TLotteryItems) : Number
            {
                if (param1 == null || param1 == null)
                {
                    return 1;
                }
                if (param1.id > param2.id)
                {
                    return 1;
                }
                if (param1.id < param2.id)
                {
                    return -1;
                }
                return 0;
            }// end function
            ;
            arr.sort(sortFunc);
            return arr;
        }// end function

        public function getItemPeciousByItemCode(param1:int) : Boolean
        {
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:TLotteryItems = null;
            var _loc_2:Boolean = false;
            var _loc_3:* = this._map[1];
            for each (_loc_4 in _loc_3)
            {
                
                for each (_loc_5 in _loc_4)
                {
                    
                    _loc_6 = _loc_5 as TLotteryItems;
                    if (!_loc_6)
                    {
                        continue;
                    }
                    if (_loc_6.itemCode == param1)
                    {
                        if (_loc_6.broadcast == 1)
                        {
                            _loc_2 = true;
                            break;
                        }
                    }
                }
            }
            return _loc_2;
        }// end function

        public static function get instance() : lotteryDrawRewardConfig
        {
            if (_instance == null)
            {
                _instance = new lotteryDrawRewardConfig;
            }
            return _instance;
        }// end function

    }
}
